#pragma once
#include <spdlog/spdlog.h>
#include <vsg/all.h>
#include <entt/entt.hpp>
#include "qbe/src/ecs/app.hpp"
#include "qlib/all.h"
#include "shader.h"

#include "qbe/src/ecs/query.hpp"

namespace qbe::utils::TempRender {
class RenderRef {
 public:
  RenderRef(qlib::Reference::s_ptr ref, int type, vsg::ref_ptr<vsg::Options> options);
  RenderRef(qlib::Reference::s_ptr ref, int type, vsg::ref_ptr<vsg::Options> options, std::function<std::vector<std::string>(uint32_t)> funvc);
  RenderRef(qlib::Reference::s_ptr ref, entt::registry& reg, ecs::Query query, int type);
  ~RenderRef();

  void updateTransform();

  qlib::Cell::s_ptr getCell() { return m_ref->cell; }

  void translate(qlib::Reference::s_ptr ref);

  void update();

  vsg::dmat3 ref_get_mat3(qlib::Reference::s_ptr ref) {
    float tx = ref->origin.x;
    float ty = ref->origin.y;
    float c = std::cos(ref->rotation);
    float s = std::sin(ref->rotation);
    float sx = 1.0 * ref->magnification;
    float sy = (ref->x_reflection ? -1.0 : 1.0) * ref->magnification;
    return vsg::dmat3{
        c * sx,  s * sy, 0,  //
        -s * sy, c * sy, 0,  //
        tx,      ty,     1,  //
    };
  }
  vsg::ref_ptr<vsg::Switch> switchObject;
  std::function<std::vector<std::string>(uint32_t)> getLayerStyleInfoOnNumFunc;

 private:
  qlib::Reference::s_ptr m_ref;
  vsg::ref_ptr<vsg::MatrixTransform> transform;

  int render_type = 0;  //0 线 1 多边形 2 点

  std::map<qlib::Tag, vsg::ref_ptr<LineMeshNode>> line_nodes;

  vsg::ref_ptr<vsg::Options> options;

  bool is_show_box = false;
};

}  // namespace qbe::utils::TempRender